<template>
  <!-- 选择仓位 -->
    <el-dialog title="信息" :visible.sync="openSelectPosition" width="800px" append-to-body :destroy-on-close="true" :before-close="beforeClose">
      <el-form ref="form" @submit.native.prevent :model="formQuery" label-width="100px" :inline="true" v-show="showSearch">
        <el-form-item label="仓位" prop="khmc">
          <el-select
            v-model="formQuery.ckcw"
            placeholder="请选择仓位"
            clearable
            @change="changePositionList"
            filterable
            :loading="selectPositionLoading"
          >
            <el-option
                v-for="item in positionList"
                :key="item.liid"
                :label="item.ckcw"
                :value="item.liid"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" size="mini" @click="handleQuery">搜 索</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading"
        :data="position2List"
        row-key="liid"
      >
        <af-table-column label="操作" align="center" class-name="small-padding fixed-width" >
            <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleSelect(scope.row)"
            >选择</el-button>
            </template>
        </af-table-column>
        <af-table-column prop="spckmc" label="仓位名称" width="100"></af-table-column>
        <af-table-column prop="ckcw" label="仓位名称" width="100"></af-table-column>
        <af-table-column prop="shengyu" label="仓位剩余容量(吨)" ></af-table-column>
        <af-table-column prop="spckbz" label="仓位备注" width="100"></af-table-column>
        <af-table-column prop="cwbz" label="仓位备注" width="100"></af-table-column>
      </el-table>
       <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
    </el-dialog>
</template>

<script>
import { selectPosition2, selectPosition } from "@/api/storage/commonGoods/warehouseMove";

export default {
  name: "WarehouseMoveSelectPosition",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //列表加载
      loading: true,
      //仓库加载
      selectPositionLoading: true,
      //弹窗状态
      openSelectPosition: false,
      // 查询参数
      formQuery: {
       	spckid:"",
        ckcw:""
      },
      //仓位选择参数
      selectPositionQuery:{
        spckid:""
      },
      //行数据
      position2List:[],
      //选择仓位列表
      positionList: [],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  methods: {
    /**获取仓库信息 */
    getList() {
      this.loading = true
      selectPosition2(this.formQuery, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.position2List = response.rows
        this.total = response.total
        this.loading = false
      });
    },
    /**选择仓位列表 */
    positionSelect() {
      this.selectPositionLoading = true
      selectPosition(this.selectPositionQuery).then(response => {
        this.positionList = response.data
        this.selectPositionLoading = false
      });
        
    },
    /**仓位过滤 */
    changePositionList() {
        this.getList()
    },
    /**仓位搜索 */
    handleQuery() {
        this.getList()
    },
    /** 选择仓位*/
    handleSelect(row) {
      this.changeSelectPosition()
      this.$emit('positionSelected', row)
    },
      /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    /**改变窗口状态 */
    changeSelectPosition() {
      this.openSelectPosition = !this.openSelectPosition;
    },
    /**关闭弹窗 */
    beforeClose(done) {
      this.close()
      done()
    },
    /**关闭弹窗 */
    close() {
      this.changeSelectPosition()
    },
    /**打开弹窗 */
    open(row) {
        this.selectPositionQuery.spckid = row.spckid
        this.formQuery.spckid = row.spckid
        this.changeSelectPosition()
        this.getList()
        this.positionSelect()
    }
  }
};
</script>
